package com.lvt.example.thinking.in.spring.bean.definition;

import com.lvt.example.thinking.in.spring.ioc.overview.domain.User;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 别名示例
 *
 * @author LT
 * @date 2021/6/6
 */
public class BeanDefinitionAliasDemo {

    public static void main(String[] args) {
        // 配置XML 文件
        // 启动Spring 应用上下文
        BeanFactory beanFactory = new ClassPathXmlApplicationContext("classpath:/META-INF/bean-definition-context.xml");
        // 通过别名获取曾用户user Bean 对象
        User zhangsanUser = (User) beanFactory.getBean("zhangsan-user");
        User user = (User) beanFactory.getBean("user");
        System.out.println("曾用户user 和 zhangsan-user 是否相同"+(zhangsanUser==user));
    }
}
